var app = getApp();
Page({
  data: {
    detail: {},
    items:'',
    receiver:{},
    memo:''
  },
  onShow: function (param){

  },
  onLoad: function (param) {
  var that = this;
   var receiverId="";
   if (param.receiverId){
     receiverId = param.receiverId;
  }
   app.ajaxJson('/pay/balance', { items: param.items, receiverId: receiverId }, function (res) {
    var json = res.data;
    if (json.code != 200) {
      wx.showModal({
        showCancel: false,
        title: '错误',
        content: json.msg ? json.msg : "500",
      })
      return;
    }
    that.setData({
      detail: json.data,
      receiver: json.data.receiver,
      items: param.items
    });
  })
  },
  created: function (){
    var that = this;
    var items=that.data.items;
    var receiverId = that.data.receiver.id;
    var memo=that.data.memo;
    app.ajaxJson('/order/create', { items: items, receiverId: receiverId,memo:memo }, function (res) {
      var json = res.data;
      if (json.code != 200) {
        wx.showModal({
          showCancel: false,
          title: '错误',
          content: json.msg ? json.msg : "500",
        })
        return;
      }
      wx.showToast({
        title: '订单创建成果',
        icon: 'success',
        duration: 1000
      });
    })
  },
  bindTextAreaBlur: function (e) {
    console.log(e.detail.value);
    this.setData({
      memo: e.detail.value
    })
  },
  addAddress: function(e){
    var that=this;
    var items = that.data.items;
    wx.navigateTo({
      url: '../select-address/index?items='+items
    });
  }
})